<?php

namespace app\admin\model\shopro\commission;

use app\admin\model\Admin;
use app\admin\model\shopro\Common;
use app\admin\model\shopro\user\Account;
use app\admin\model\shopro\user\User as UserModel;

class MonthlyCompliance extends Common
{

    const COMMISSION_REWARD_STATUS_PENDING = 0;  // 未结算、待入账
    const COMMISSION_REWARD_STATUS_ACCOUNTED = 1;  // 已结算、已入账
    const COMMISSION_REWARD_STATUS_CANCEL = -1;  // 已取消
    const COMMISSION_REWARD_STATUS_BACK = -2;  // 已退回

    protected $name = 'monthly_compliance';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $type = [
        'grant_time' => 'timestamp',
    ];
    protected $append = [
        'status_text',
    ];

    public function statusList()
    {
        return [
            0 => '未结算',
            1 => '已结算'
        ];
    }


    /**
     * 待入账
     */
    public function scopePending($query)
    {
        return $query->where('status', self::COMMISSION_REWARD_STATUS_PENDING);
    }
    /**
     * 已退回
     */
    public function scopeBack($query)
    {
        return $query->where('status', self::COMMISSION_REWARD_STATUS_BACK);
    }

    /**
     * 已入账
     */
    public function scopeAccounted($query)
    {
        return $query->where('status', self::COMMISSION_REWARD_STATUS_ACCOUNTED);
    }

    /**
     * 已取消
     */
    public function scopeCancel($query)
    {
        return $query->where('status', self::COMMISSION_REWARD_STATUS_CANCEL);
    }

    public function user()
    {
        return $this->belongsTo(UserModel::class, 'user_id', 'id')->field('id, nickname, avatar, mobile,ID_number');
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class, 'admin_id', 'id')->field('id, nickname, avatar, mobile');
    }
    //关联银行卡
    public function account(){
        return $this->belongsTo(Account::class, 'user_id', 'user_id')->where(["type"=>"bank"])->field('account_header,account_name,type,user_id,account_no');
    }
}
